package com.ytf.test.third;

/**
 * @author: YTF
 * @date: 2024/9/12 10:39
 * @version: 1.0
 * @description: 分配
 */
public class Assignment {
    public static void main(String[] args) {
        Tank tank1 = new Tank();
        Tank tank2 = new Tank();
        tank1.level = 1;
        tank2.level = 2;
        System.out.println("tank1="+tank1.level+", tank2="+tank2.level);
        tank1.level=tank2.level;
        System.out.println("tank1.level=tank2.level; tank1="+tank1.level+", tank2="+tank2.level);
        tank1.level=10;
        System.out.println("tank1.level=10; tank1="+tank1.level+", tank2="+tank2.level);
        tank1=tank2;
        System.out.println("tank1=tank2; tank1="+tank1.level+", tank2="+tank2.level);
        tank1.level=11;
        System.out.println("tank1.level=11; tank1="+tank1.level+", tank2="+tank2.level);
        /**
         * output:
         * tank1=1, tank2=2
         * tank1.level=tank2.level; tank1=2, tank2=2
         * tank1.level=10; tank1=10, tank2=2
         * tank1=tank2; tank1=2, tank2=2
         * tank1.level=11; tank1=11, tank2=11
         * 总结：
         *  属性赋值只保存值
         *  类赋值是将引用地址修改
         *  类赋值后修改会影响赋值类
         */
    }
}

class Tank{
    int level;
}
